package cn.bonoon.controllers.parsers;

import javax.servlet.http.HttpServletRequest;

import cn.bonoon.kernel.events.PanelEvent;
import cn.bonoon.kernel.menus.ModuleManager;
import cn.bonoon.kernel.menus.privileges.PrivilegeInspector;
import cn.bonoon.kernel.security.LogonUser;
import cn.bonoon.kernel.web.KeyChecker;
import cn.bonoon.kernel.web.controllers.PanelParser;
import cn.bonoon.kernel.web.models.FrameModel;

public class UserPanelParser implements PanelParser{
	private final ModuleManager moduleManager;
	
	public UserPanelParser(ModuleManager moduleManager){
		this.moduleManager = moduleManager;
	}
	
	@Override
	public PanelEvent parse(String mid, HttpServletRequest request, LogonUser user) throws Exception {
		FrameModel model = new FrameModel(mid, request);
		model.addObject(KeyChecker.CHECKER_PROPERTY_NAME, KeyChecker.EMPTY);
		return new PanelEvent(model, moduleManager.item(mid), user, PrivilegeInspector.ALL);
	}

}
